package com.japp.manager.web;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.japp.base.BaseAction;
import com.japp.manager.bean.EngageInBean;
import com.japp.manager.service.EngageInService;
import com.japp.sys.bean.SelectBean;
import com.japp.sys.mapper.DpMapper;
import com.japp.tools.common.Common;
import com.japp.tools.common.JappLog;
/**
 * 研究报告
 * @author Administrator
 *
 */
@Scope("prototype")
@Controller
public class EngageInAction extends BaseAction<EngageInBean> {

	private static final long serialVersionUID = -5677670163048708848L;
	@Autowired
	private EngageInService enService;
	@Autowired
	private DpMapper dpMapper;
	private EngageInBean en = new EngageInBean();

	private Map<String, String> map = null;
	
	/**
	 * 查询研究报告
	 * @return
	 */
	public String queryEngageIn(){
		String power = session.getAttribute("u_power").toString();
		String dpid = session.getAttribute("userltd").toString();
		//String dpcode = session.getAttribute("userltdcode").toString();
		String usercode = session.getAttribute("u_code").toString();
		//部门
		if("2".equals(power)){
			en.setEn_submit_dpid(dpid);
		//业务员
		}else if("3".equals(power)){
			en.setEn_submit_ucode(usercode);
		}
		try {
			List<SelectBean> list = dpMapper.queryDpSelectAll();		//部门
			json_val = Common.formtSelectToJson(list);
		} catch (Exception e) {
			JappLog.log.error("查询部门或转换Json错误",e);
		}
		page = enService.getPage(page, en);
		return SUCCESS;
	}
	/**
	 * 查看
	 * @return
	 */
	public String findEngageInView(){
		if(en.getEn_id()!=0){
			en = enService.findEngageInById(en.getEn_id());
			obj_date = en.getDates();
			obj_cdate = en.getCdates();
		}
		return "enView";
	}
	/**
	 * 欲新增 以及更新 
	 * @return enView enDetil
	 */
	public String findEngageInDetil(){
		if(en.getEn_id()!=0){
			en = enService.findEngageInById(en.getEn_id());
			obj_date = en.getDates();
			obj_cdate = en.getCdates();
		}
		return "enEdit";
	}
	/**
	 * 删除
	 * @return
	 */
	public void deleteEngageInById(){
		int rel = enService.deleteEngageIn(keys);
		if(rel>0){
			result = "删除成功!";
		}else {
			result = "删除失败!";
		}
		wPrint(result);
	}
	/**
	 * 更新
	 * @return
	 */
	public void updateEngageInById(){
		en.setEn_submit_date(obj_date+obj_cdate);
		en.setDates(obj_date);
		en.setCdates(obj_cdate);
		int rel = enService.updateEngageIn(en);
		if(rel>0){
			result = String.valueOf(en.getEn_id());
		}else {
			result = "error";
		}
		wPrint(result);
	}
	/**
	 * 新增
	 */
	public void insertEngageInById(){
		en.setEn_submit_date(obj_date+obj_cdate);
		en.setDates(obj_date);
		en.setCdates(obj_cdate);
		int rel = enService.insertEngageIn(en);
		if(rel>0&&en.getEn_id()!=0){
			result = ""+en.getEn_id();
		}else {
			result = "0";
		}
		wPrint(result);
	}
	public EngageInBean getEn() {
		return en;
	}
	public void setEn(EngageInBean en) {
		this.en = en;
	}
	public Map<String, String> getMap() {
		return map;
	}
	public void setMap(Map<String, String> map) {
		this.map = map;
	}
	
}

